package service

import (
	"gitee.com/gopher2011/mall/app/dao"
	"time"
)

// 全局公开对象
var SmsFlashPromotion = smsFlashPromotionService{}

// 私有对象，所有的方法都绑定到这个结构体上。
type smsFlashPromotionService struct{}

func (p *smsFlashPromotionService) Create(arg dao.SmsFlashPromotion) (int64, error) {
	arg.CreateTime = time.Now()
	return dao.SmsFlashPromotionDao.Insert(arg)
}

func (p *smsFlashPromotionService) Update(id int64, arg dao.SmsFlashPromotion) (int64, error) {
	u := dao.SmsFlashPromotion{
		Id:         id,
		Title:      arg.Title,
		StartDate:  arg.StartDate,
		EndDate:    arg.EndDate,
		Status:     arg.Status,
		CreateTime: time.Now(),
	}
	return dao.SmsFlashPromotionDao.UpdateById(u)
}

func (p *smsFlashPromotionService) UpdateStatus(id int64, status int32) (int64, error) {
	return dao.SmsFlashPromotionDao.UpdateStatus(id, status)
}

func (p *smsFlashPromotionService) Delete(id int64) (int64, error) {
	return dao.SmsFlashPromotionDao.DeleteById(id)
}

func (p *smsFlashPromotionService) GetItem(id int64) (dao.SmsFlashPromotion, error) {
	return dao.SmsFlashPromotionDao.SelectById(id)
}

func (p *smsFlashPromotionService) List(arg dao.SmsFlashPromotionList) ([]dao.SmsFlashPromotion, error) {
	return dao.SmsFlashPromotionDao.List(arg)
}
